package bolao.view;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public abstract class TelaSalvarCancelar {
	
	protected JFrame janela;
	
	protected abstract int salvar();
	
	protected JPanel criaBotoes(){
		JPanel botoes = new JPanel();
		botoes.setLayout(new GridLayout(1,2));

		JButton salvar = new JButton("Salvar");
		salvar.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent e) {				
				int resultado = salvar();
				if(resultado == 0){
					janela.dispose();
					new TelaInicial().abrir();
				}
			}

		});
		botoes.add(salvar, BorderLayout.SOUTH);

		JButton cancelar = new JButton("Cancelar");
		botoes.add(cancelar, BorderLayout.SOUTH);
		cancelar.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent e) {				
				int result = JOptionPane.showConfirmDialog(janela, 
						"Voce perdera todas as informacoes, deseja realmente sair?", 
						"Cancelar", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
				if(result == JOptionPane.OK_OPTION){
					new TelaInicial().abrir();
					janela.dispose();
				}
			}

		});

		return botoes;
	}	

}
